﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <title>假期</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageStyles" runat="server">
    <style type="text/css">
        .entryExplanation
        {
            font-weight: bolder;
            font-size: 14px;
            background-color: #FFEC8B;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageScripts" runat="server">
    <script type="text/javascript">
    //************* URL常量

    var URL_AUDIT_LEAVE = '/attendance/DoAuditLeave';

    //************* 全局变量

    var g_Var = {
        'leaveInfo': null
    };
    //************* 常量定义

    var StaticResource = {
        'isAgreed': '已通过审核',
        'isNotAgreed': '未通过审核'
    };
    //************* Accessor访问器

    var EzAccessor = {};
    if (ezmock.IS_MOCKED) {
      
        EzAccessor = mockEzAccessor;
    } else {
        var realEzAccessor = {
            'doUpdateAuditInfo': function (LeaveInfoId, AuditNote, IsAgree) {
                $('#auditSuggestion').attr('disabled', true);
                $('.page-submit').ajaxBusyProgress();
                //审核假期
                $.post(URL_AUDIT_LEAVE,
                   { "isAgreed": IsAgree, "leaveInfoId": LeaveInfoId, "auditNote": AuditNote },
                   function (e) {
                        if (e.Status == "Success") {
                        var url = '/attendance/auditLeave?leaveId={leaveId}';
                        url = url.replace("{leaveId}", e.Data.leaveId);
                        $.redirectAndDisplayInfo(url, e);
                        } else {
                            $('.page-submit').ajaxBusyProgress('reset');
                        }
                   });

            },
            'getBasicInfo': function () {
                g_Var['leaveInfo'] = <%=ViewData["LeaveInfo"] %>;
            }
        };
        EzAccessor = realEzAccessor;
    }


    function toFullTimeFormat(dateTime) {
        var time = Date.fromEpoch(dateTime);
        var fullTime = time.toFullDateAndDay()
                       + " " + time.toFullTime();
        return fullTime;
    }

    function bindHeadTips() {

        var applyTime = Date.fromEpoch(g_Var['leaveInfo']['CreateOn']);
        var temp = $('#department').html();
        var deptName = temp.replace("{deptName}", g_Var['leaveInfo']['User']['Dept']['DeptName']);

        $('#department').html(deptName);
        $('#applyName').html(g_Var['leaveInfo']['User']['Name']);
        $('#CreateTime').html(applyTime.toNiceTime());
        $('#applyLeaveType').html(g_Var['leaveInfo']['LeaveTypeName']);

    }

    function bindLeaveInfoDetails() {

        var fullStartTime = toFullTimeFormat(g_Var['leaveInfo']['StartTime']);
        var fullEndTime = toFullTimeFormat(g_Var['leaveInfo']['EndTime']);

        $('#lblApplyLeaveType').html(g_Var['leaveInfo']['LeaveTypeName']);
        $('#lblCreateTimeBegin').html(fullStartTime);
        $('#lblCreateTimeEnd').html(fullEndTime);
        $('#lblDescription').html(g_Var['leaveInfo']['Description']);

    }

    function bindAuditDetails() {

        if (g_Var['leaveInfo']["IsAudited"]) {

            var fullAuditTime = toFullTimeFormat(g_Var['leaveInfo']['AuditTime']);
            var auditer = g_Var['leaveInfo']['AuditUser']['Name'];
            var auditStatus = g_Var['leaveInfo']['IsAgreed'];
            var auditNote = g_Var['leaveInfo']['AuditNote'];

            //审核btn不可见 
            $('.page-submit').hide();
            //审核信息 
            $('#auditNewLeave').hide();
            $('#audited').show();
            $('#lblAuditer').html(auditer);
            $('#lblAuditTime').html(fullAuditTime);
            $('#lblAuditNote').html(auditNote);

            if (auditStatus) {
                $('#lblAuditStatus').html(StaticResource['isAgreed']);
            }
            else {

                $('#lblAuditStatus').html(StaticResource['isNotAgreed']);
            }
        }
        else {
            //审核btn可见
            $('.page-submit').show();
            //审核意见
            $('#auditNewLeave').show();
            $('#audited').hide();
        }

    }



    function doIsAgreed(isAgree) {

        var LeaveInfoId = g_Var['leaveInfo']['Id'];

        g_Var['leaveInfo']['IsAudited'] = true;
        g_Var['leaveInfo']['IsAgreed'] = isAgree;

        g_Var['leaveInfo']['AuditNote'] = $('#auditSuggestion').val().htmlEncode();

        EzAccessor.doUpdateAuditInfo(LeaveInfoId, g_Var['leaveInfo']['AuditNote'], g_Var['leaveInfo']['IsAgreed']);


    }

    function initPage() {
        EzTipsManager.addTipBox('#tip_Remind', 'tipRemind');
        EzTipsManager.addTipBox('#tip_ApplyInfo', 'tipApplyInfo');
        EzTipsManager.showTipBox('tipRemind');
        EzTipsManager.showTipBox('tipApplyInfo');

        EzAccessor.getBasicInfo();

        bindHeadTips();
        bindLeaveInfoDetails();
        bindAuditDetails();

    }


    function initPageEvent() {
        $('#btnAgree').click(function () {
            doIsAgreed(true);
        });
        $('#btnDisagree').click(function () {

            doIsAgreed(false);
        });
        $('#auditSuggestion').focus();

    }


    $(function () {
        initPage();
        initPageEvent();
    });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PageHead" runat="server">
    <%
        Html.RenderPartial("_sayHello"); %>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageContent" runat="server">
    <div id="page-head" class="page-head">
        <img src="../../Content/icons/attendance_auditLeave.png" style="width: 48px; height: 48px;"
            alt="auditLeave" />
        <span class="title">假期审核</span>
    </div>
    <div id="page-body">
        <ul class="fieldslist">
            <li>
                <div class="l">
                    <label>
                        请假类别:</label>
                </div>
                <div class="r">
                    <strong><span id="lblApplyLeaveType" style="margin-left: 10px;"></span></strong>
                </div>
            </li>
            <li>
                <div class="l">
                    <label>
                        开始时间:</label>
                </div>
                <div class="r">
                    <span id="lblCreateTimeBegin" style="margin-left: 10px;"></span>
                </div>
            </li>
            <li>
                <div class="l">
                    <label>
                        结束时间:</label>
                </div>
                <div>
                    <label id="lblCreateTimeEnd" style="margin-left: 10px;">
                    </label>
                </div>
            </li>
            <li>
                <div class="l">
                    <label>
                        原因描述:</label>
                </div>
                <div class="r">
                    <span id="lblDescription" disabled="disabled" style="margin-left: 10px;"></span>
                </div>
            </li>
        </ul>
        <div id="auditNewLeave">
            <div class="formBox" style="margin: 20px 0 0 0;">
                <div>
                    <span class="entryExplanation">填写审核意见</span> <span>如果不填写将置空。</span>
                </div>
                <textarea id="auditSuggestion" cols="30" rows="4" style="margin-left: 10px;"></textarea>
            </div>
        </div>
        <ul class="fieldslist" id="audited" style="display: none; margin: 20px 0 0 0;">
            <li>
                <div>
                    <ul>
                        <li>
                            <div class="l">
                                <label>
                                    审核状态:</label>
                            </div>
                            <div class="r">
                                <span id="lblAuditStatus" style="margin-left: 10px;"></span>
                            </div>
                        </li>
                        <li>
                            <div class="l">
                                <label>
                                    审核人:</label>
                            </div>
                            <div class="r">
                                <span id="lblAuditer" style="margin-left: 10px;"></span>
                            </div>
                        </li>
                        <li>
                            <div class="l">
                                <label>
                                    审核时间:</label>
                            </div>
                            <div class="r">
                                <span id="lblAuditTime" style="margin-left: 10px;"></span>
                            </div>
                        </li>
                        <li>
                            <div class="l">
                                <label>
                                    审核意见:</label>
                            </div>
                            <div class="r">
                                <span id="lblAuditNote" style="margin-left: 10px;"></span>
                            </div>
                        </li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
    <div class="page-submit" style="display: none;">
        <div id="btnAgree" style="margin-left: 20px;">
            同意</div>
        <script type="text/javascript">
            $(function () {
                $("#btnAgree").button({
                    icons: {
                        primary: "ui-icon-circle-check"
                    },
                    text: true
                });
            });
        </script>
        或者 <a id="btnDisagree">拒绝</a>
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="PageShortcut" runat="server">
    <div id="shortcuts" class="box">
        <a class="btn-shortcut" href="/attendance/auditList">员工请假记录</a>
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="PageFoot" runat="server">
    <div id="tip_Remind" style="display: none;">
        <h1>
            小贴士:</h1>
        <p class="indent">
        </p>
    </div>
    <div id="tip_ApplyInfo" style="display: none;" class="tip-succ">
        <h1>
            假期申请:</h1>
        <div class="indent">
            <p>
                <span id="applyName"></span><span id="department">({deptName})</span></p>
            <p>
                <span id="CreateTime"></span>
            &nbsp;提交申请</div>
    </div>
</asp:Content>
